﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using vensoft.BussinesLogic;
using vensoft.Entities;

namespace vensoft.Win32
{
    public partial class frmGestionarCategoria : Form
    {
        ICategoriaBL categoriaBL;
       
        public frmGestionarCategoria()
        {
            InitializeComponent();
        }
        public Int32 estadoBotones { get; set; }

        private void frmGestionarCategoria_Load(object sender, EventArgs e)
        {
            categoriaBL = new CategoriaBL();
            categoriaBindingSource.DataSource = categoriaBL.GetAllFromCategoria();
            if (estadoBotones == 1)
            {
                btnSeleccionar.Visible = true;
                btnNuevo.Visible = false;
                btnEditar.Visible = false;
                btnEliminar.Visible = false;
               
            }
            else
            {
                btnSeleccionar.Visible = false;
                btnNuevo.Visible = true;
                btnEditar.Visible = true;
                btnEliminar.Visible = true;
              
            }
            
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnNuevo_Click(object sender, EventArgs e)
        {
            frmAECategoria aecategoria = new frmAECategoria();
            aecategoria.Nuevo();
            aecategoria.ShowDialog();
        }

        private void btnActualizarDatos_Click(object sender, EventArgs e)
        {
            categoriaBL = new CategoriaBL();
            categoriaBindingSource.DataSource = categoriaBL.GetAllFromCategoria();
           
        }

        private void btnEditar_Click(object sender, EventArgs e)
        {
            frmAECategoria aecategoria = new frmAECategoria();
            aecategoria.CurrentCatego = categoriaBindingSource.Current as Categoria;
            aecategoria.Editar();
            aecategoria.ShowDialog();
          
        }

        public Int32 Validacion { get; set; }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Validacion = 1;
            this.Close();
        }

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("¿Estas seguro que deseas eliminar?", "ALERTA", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Categoria curentCategoria = categoriaBindingSource.Current as Categoria;
                categoriaBL.EliminarCategoria(curentCategoria);
                categoriaBindingSource.RemoveCurrent();
                
            }
        }

        private void btnSeleccionar_Click(object sender, EventArgs e)
        {
            CurrentCateg = categoriaBindingSource.Current as Categoria;
            
            this.Close();

        }
        public Categoria CurrentCateg { get; set; }

        private void txtBuscarCategoria_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                categoriaBL = new CategoriaBL();
                categoriaBindingSource.DataSource = categoriaBL.GetFromCategoriaByNombre(txtBuscarCategoria.Text);
                
            }
        }
       

        private void txtBuscarCategoria_MouseClick(object sender, MouseEventArgs e)
        {
            switch (e.Button)
            {
                case (MouseButtons.Left):

                    txtBuscarCategoria.Text = null;
                    break;
            }
        }

    }
}
